package com.yibo.message.controller;

import com.yibo.message.service.MessageCheckWordService;
import com.yibo.support.helper.ResultHelper;
import com.yibo.support.pojo.IResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.yibo.support.constant.ApiUrlConstant.PUBLIC_URL;

@RestController
@RequestMapping(PUBLIC_URL+"/checkWord")
public class MessageCheckWordController {

    @Resource
    private MessageCheckWordService messageCheckWordService;

    @ApiOperation("邮件发送注册验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "邮箱", type = "string", required = true),
            @ApiImplicitParam(name = "type", value = "验证码类型", type = "string", required = true)
    })
    @PostMapping("/send/email/register/checkword")
    public IResult<Integer> send(@RequestParam(value = "email") String email,
                                 @RequestParam(value = "type") String type) {
        return ResultHelper.result("发送成功", messageCheckWordService.send(email,type));
    }


    @ApiOperation("通过邮箱以及验证码类型，查询邮箱当前的验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "邮箱", type = "string", required = true),
            @ApiImplicitParam(name = "type", value = "验证码类型", type = "string", required = true)
    })
    @PostMapping("/email/checkWord")
    public IResult<String> emailWord(@RequestParam(value = "email") String email,
                                     @RequestParam(value = "type") String type) {
        return ResultHelper.result("查询成功", messageCheckWordService.emailCheckWord(email, type));
    }


    @PostMapping("/checkWord/delete")
    public IResult<Integer> deleteCheckWord(@RequestParam(value = "email") String email,
                                            @RequestParam(value = "type") String type) {
        return ResultHelper.result("删除成功", messageCheckWordService.removeCheckWord(email, type));
    }

}
